package td.pt.widget;

import td.client.ui.Button;
import td.domain.DemoStore;
import td.domain.TagDef;
import td.pt.other.TagTreeModel;

import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.CellBrowser;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.SingleSelectionModel;
import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.mvp.client.PopupViewImpl;

public class TagTreePopupView extends PopupViewImpl implements
		TagTreePopupPresenter.MyView {

	private final Widget widget;

	@UiField(provided = true)
	CellBrowser tagBrowser;
	@UiField
	Button selectTag;
	@UiField
	Button tagThought;
	@UiField
	Button cancel;
	@UiField
	Label browserPurposeDescription;

	@UiField
	RadioButton orderAlphabetic;
	@UiField
	RadioButton orderNumberOfThoughts;
	@UiField
	RadioButton orderNumberOfReads;

	TagTreeModel model;
	SingleSelectionModel<TagDef> selectionModel;

	public interface Binder extends UiBinder<Widget, TagTreePopupView> {
	}

	@Inject
	public TagTreePopupView(final EventBus eventBus, final Binder binder) {
		super(eventBus);

		selectionModel = new SingleSelectionModel<TagDef>();
		model = new TagTreeModel(selectionModel);
		tagBrowser = new CellBrowser(model, DemoStore.db().rootTag);

		widget = binder.createAndBindUi(this);
	}

	public void refresh() {
		selectionModel.setSelected(selectionModel.getSelectedObject(), false);
		model.refresh();
	}

	@Override
	public Widget asWidget() {
		return widget;
	}

	public Button getSelectTag() {
		return selectTag;
	}

	public Button getTagThought() {
		return tagThought;
	}

	public Button getCancel() {
		return cancel;
	}

	public CellBrowser getTagBrowser() {
		return tagBrowser;
	}

	public Label getBrowserPurposeDescription() {
		return browserPurposeDescription;
	}

	public SingleSelectionModel<TagDef> getSelectionModel() {
		return selectionModel;
	}

	public RadioButton getOrderAlphabetic() {
		return orderAlphabetic;
	}

	public RadioButton getOrderNumberOfThoughts() {
		return orderNumberOfThoughts;
	}

	public RadioButton getOrderNumberOfReads() {
		return orderNumberOfReads;
	}
}
